using System;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace Coding4Fun.Phone.Controls
{
	public abstract class ColorBaseControl : Control
	{
		public delegate void ColorChangedHandler(object sender, Color color);
		private ColorBaseControl.ColorChangedHandler colorChangedHandler_0;
		public static readonly DependencyProperty ColorProperty = DependencyProperty.Register("Color", typeof(Color), typeof(ColorBaseControl), new PropertyMetadata(new PropertyChangedCallback(ColorBaseControl.OnColorChanged)));
		public static readonly DependencyProperty SolidColorBrushProperty = DependencyProperty.Register("SolidColorBrush", typeof(SolidColorBrush), typeof(ColorBaseControl), new PropertyMetadata(null));
		public event ColorBaseControl.ColorChangedHandler ColorChanged
		{
			add
			{
				ColorBaseControl.ColorChangedHandler colorChangedHandler = this.colorChangedHandler_0;
				ColorBaseControl.ColorChangedHandler colorChangedHandler2;
				do
				{
					colorChangedHandler2 = colorChangedHandler;
					ColorBaseControl.ColorChangedHandler colorChangedHandler3 = (ColorBaseControl.ColorChangedHandler)Delegate.Combine(colorChangedHandler2, value);
					colorChangedHandler = Interlocked.CompareExchange<ColorBaseControl.ColorChangedHandler>(ref this.colorChangedHandler_0, colorChangedHandler3, colorChangedHandler2);
				}
				while (colorChangedHandler != colorChangedHandler2);
			}
			remove
			{
				ColorBaseControl.ColorChangedHandler colorChangedHandler = this.colorChangedHandler_0;
				ColorBaseControl.ColorChangedHandler colorChangedHandler2;
				do
				{
					colorChangedHandler2 = colorChangedHandler;
					ColorBaseControl.ColorChangedHandler colorChangedHandler3 = (ColorBaseControl.ColorChangedHandler)Delegate.Remove(colorChangedHandler2, value);
					colorChangedHandler = Interlocked.CompareExchange<ColorBaseControl.ColorChangedHandler>(ref this.colorChangedHandler_0, colorChangedHandler3, colorChangedHandler2);
				}
				while (colorChangedHandler != colorChangedHandler2);
			}
		}
		public Color Color
		{
			get
			{
				return (Color)base.GetValue(ColorBaseControl.ColorProperty);
			}
			set
			{
				base.SetValue(ColorBaseControl.ColorProperty, value);
			}
		}
		public SolidColorBrush SolidColorBrush
		{
			get
			{
				return (SolidColorBrush)base.GetValue(ColorBaseControl.SolidColorBrushProperty);
			}
			private set
			{
				base.SetValue(ColorBaseControl.SolidColorBrushProperty, value);
			}
		}
		private static void OnColorChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			ColorBaseControl colorBaseControl = dependencyObject_0 as ColorBaseControl;
			if (colorBaseControl != null)
			{
				colorBaseControl.UpdateLayoutBasedOnColor();
				colorBaseControl.SolidColorBrush = new SolidColorBrush((Color)dependencyPropertyChangedEventArgs_0.get_NewValue());
			}
		}
		protected internal virtual void UpdateLayoutBasedOnColor()
		{
		}
		protected internal void ColorChanging(Color color)
		{
			this.Color = color;
			this.SolidColorBrush = new SolidColorBrush(this.Color);
			if (this.colorChangedHandler_0 != null)
			{
				this.colorChangedHandler_0(this, this.Color);
			}
		}
	}
}
